home *** CD-ROM | disk | FTP | other *** search
- Path: medtronic.com!usenet
- From: Peter Joseph Kovach <peter.joseph.kovach@medtronic.com>
- Newsgroups: comp.lang.c++
- Subject: NEED HELP ON A WINDOWS BITMAP BUTTON IN A DIALOG BOX PROBLEM !!
- Date: 8 Mar 1996 16:10:47 GMT
- Organization: Medtronic
- Message-ID: <4hpm67$3pt@gazette.medtronic.com>
- NNTP-Posting-Host: 144.15.63.237
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
- In the following code, the system keeps crashing when I do the autoload
- of the bitmap button. (Please look in the code below for the #ifdef PETE
- line. It is there.
-
- Is there something else I need to do to initialize the button. It seems
- many of its, and potentially its parents, values are not initialized so
- they are garbage.
-
- If you can help, please let me know and I could send potentially send
- you the whole project if you needed it. The code compiles, but when it
- attempts to generate this dialog box, it dies.
-
- Thank you in advance!
-
-
-
-
- #include "stdafx.h"
- #include <stdio.h>
- #include <process.h>
- #include "resource.h"
-
- #include "introtst.h"
- #include "mainfrm.h"
- #include "introdoc.h"
- #include "introvw.h"
- #include "introscr.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- CMainFrame *pMainFrame;
- #define NUMENTRIES 128
- CBrush pBrush;
- HPALETTE hpal;
- PALETTEENTRY ape[NUMENTRIES];
- int red, green, blue;
- int cColors = NUMENTRIES;
- CRect *lpr = NULL, *UpRect;
-
- LOGFONT lf, lf2;
- PAINTSTRUCT ps; // paint structure
- CClientDC *dc;
-
-
- /* Create the "---" pen */
-
- HPEN hDashPen = CreatePen(PS_DASH, /* style */
- 1, /* width */
- RGB(0, 0, 0)); /* color */
-
- /* Create the standard pen */
-
- HPEN hSolidPen = CreatePen(PS_SOLID, /* style */
- 1, /* width */
- RGB(0, 0, 0)); /* color */
-
- // Create a white pen
- HPEN hWhitePen = CreatePen(PS_SOLID, /* style */
- 1, /* width */
- RGB(255, 255, 255)); /* color */
-
- /* Create the "->->->" pen */
-
- HPEN hDotPen = CreatePen(2, /* style */
- 1, /* width */
- RGB(0, 0, 0)); /* color */
-
-
- // Draw something
- HPEN hOldPen; // old pen handle
-
- introscreen *intro;
-
-
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CIntrotstApp
-
- BEGIN_MESSAGE_MAP(CIntrotstApp, CWinApp)
- //{{AFX_MSG_MAP(CIntrotstApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- // NOTE - the ClassWizard will add and remove mapping
- macros here.
- // DO NOT EDIT what you see in these blocks of
- generated code!
- //}}AFX_MSG_MAP
- // Standard file based document commands
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- // Standard print setup command
- ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CIntrotstApp construction
-
- CIntrotstApp::CIntrotstApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // The one and only CIntrotstApp object
-
- CIntrotstApp NEAR theApp;
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CIntrotstApp initialization
-
- BOOL CIntrotstApp::InitInstance()
- {
- // Standard initialization
- // If you are not using these features and wish to reduce the
- size
- // of your final executable, you should remove from the
- following
- // the specific initialization routines you do not need.
-
- SetDialogBkColor(); // Set dialog background color to gray
- LoadStdProfileSettings(); // Load standard INI file options
- (including MRU)
-
- // Register the application's document templates. Document
- templates
- // serve as the connection between documents, frame windows and
- views.
-
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_INTROTTYPE,
- RUNTIME_CLASS(CIntrotstDoc),
- RUNTIME_CLASS(CMDIChildWnd), // standard MDI child
- frame
- RUNTIME_CLASS(CIntrotstView));
- AddDocTemplate(pDocTemplate);
-
- // create main MDI Frame window
- pMainFrame = new CMainFrame;
- int test = IDR_MAINFRAME;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME,
- WS_VISIBLE|WS_OVERLAPPEDWINDOW, NULL, NULL))
- return FALSE;
- m_pMainWnd = pMainFrame;
-
- if (m_lpCmdLine[0] != '\0')
- {
- // TODO: add command line processing here
- }
-
- // The main window has been initialized, so show and update it.
- pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
- pMainFrame->UpdateWindow();
-
- // create a new (empty) document
- //OnFileNew();
- intro = new introscreen(pMainFrame);
- intro->ShowWindow(SW_SHOWNORMAL);
- intro->UpdateWindow();
- pMainFrame->UpdateWindow();
-
- // The following initializes a LOGPALETTE structure and an array
- of
- // PALETTEENTRY structures, and then uses the CreatePalette
- function
- // to retrieve a handle of a logical palette:
-
- LOGPALETTE *plgpl = (LOGPALETTE*) LocalAlloc(LPTR,
- sizeof(LOGPALETTE) + cColors * sizeof(PALETTEENTRY));
-
- plgpl->palNumEntries = cColors;
- plgpl->palVersion = 0x300;
-
- for (int i = 0, red = 0, green = 127, blue = 127; i < NUMENTRIES;
- i++, red += 1, green += 1, blue += 1)
- {
- ape[i].peRed =
- plgpl->palPalEntry[i].peRed = LOBYTE(red);
- ape[i].peGreen =
- plgpl->palPalEntry[i].peGreen = LOBYTE(green);
- ape[i].peBlue =
- plgpl->palPalEntry[i].peBlue = LOBYTE(blue);
- ape[i].peFlags =
- plgpl->palPalEntry[i].peFlags = PC_RESERVED;
- }
-
-
- hpal = CreatePalette((LPLOGPALETTE)plgpl);
- if (!hpal)
- {
- // Error("CreatePalette() failed");
- return -1;
- }
- SelectPalette((HDC)&(intro->dc), hpal, 0); //(HDC)dcTest->m_hDC
- RealizePalette((HDC)&(intro->dc));
-
- // Create a solid fill brush pattern to fill the chart data
- pBrush.CreateSolidBrush(PALETTEINDEX(0));
-
- // Finally free the palette
- LocalFree((HLOCAL) plgpl);
-
-
- lpr = new CRect();
-
-
- return TRUE;
- }
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // Implementation
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV
- support
- //{{AFX_MSG(CAboutDlg)
- // No message handlers
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- // App command to run the dialog
- void CIntrotstApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // CIntrotstApp commands
-
-
- // Implement CDialog derived IntroScreen putting bitmap into background
- // of a dialog box with StretchBlt() in WM_ERASEBKGND handler.
- //
- /////////////////////////////////////////////////////////////////////////
- ////
- introscreen::introscreen(CWnd* pParent /*=NULL*/)
- : CDialog(introscreen::IDD, pParent)
- {
- //{{AFX_DATA_INIT(introscreen)
- // NOTE: the ClassWizard will add member initialization
- here
- //}}AFX_DATA_INIT
-
- Create( IDD_SELECTPROG , NULL);
-
- intro = this;
- }
-
- introscreen::~introscreen()
- {
- delete button1;
- delete button2;
- delete button3;
- delete button4;
- }
-
- void introscreen::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(introscreen)
- DDX_Control(pDX, IDC_IDST, m_IDST);
- DDX_Control(pDX, IDC_IDITR, m_IDITR);
- DDX_Control(pDX, IDC_IDINS, m_IDINS);
- DDX_Control(pDX, IDC_IDDP, m_IDDP);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(introscreen, CDialog)
- //{{AFX_MSG_MAP(introscreen)
- ON_BN_CLICKED(IDC_IDDP, OnIddp)
- ON_BN_CLICKED(IDC_IDINS, OnIdins)
- ON_BN_CLICKED(IDC_IDITR, OnIditr)
- ON_BN_CLICKED(IDC_IDST, OnIdst)
- ON_WM_CTLCOLOR()
- ON_WM_DESTROY()
- ON_WM_CREATE()
- ON_WM_SHOWWINDOW()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////
- ////
- // introscreen message handlers
-
- void introscreen::OnIddp()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void introscreen::OnIdins()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void introscreen::OnIditr()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- void introscreen::OnIdst()
- {
- // TODO: Add your control notification handler code here
-
- }
-
- //***********************************************************************
- // IntroScreen::OnCtlColor()
- //
- // Purpose:
- //
- // SetBkMode() to TRANSPARENT so text drawing won't use dialogs
- // background color.
- // Return a handle to a hollow brush, so no other piece of the
- // bitmap in the background will be erased.
- //
- // Parameters:
- //
- // CDC* pDC - Device context for drawing control
- // CWnd* pWnd - Pointer to control CWnd
- // UINT nCtlColor - Control type (ie. CTLCOLOR_STATIC)
- //
- // Returns:
- //
- // HBRUSH (Handle of background brush to paint background with)
- //
- // Comments:
- //
- // This function could be left. The main difference will be that
- // text will show up with a block of the background color around
- it.
- //
-
- // History:
- //
- // Date Comment Initials
- // ======== ================================================= ========
- //***********************************************************************
- HBRUSH introscreen::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- // Have text and controls be painted smoothly over bitmap
- // without using default background color
- pDC->SetBkMode( TRANSPARENT );
- return m_brush;
-
- // Do not call base class, which, sets background color differently
- // return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- }
-
-
-
- //***********************************************************************
- // IntroScreen::OnDestroy()
- //
- // Purpose:
- //
- // Select old bitmap back into memory DC before it is destroyed
- // when CPaintDlg object is.
- // DeleteObject() the bitmap which had been loaded.
- //
- // Parameters:
- //
- // None.
- //
- // Returns:
- //
- // None.
- //
- // Comments:
- //
- // History:
- //
- // Date Comment Initials
- // ======== ================================================= ========
- //***********************************************************************
- void introscreen::OnDestroy()
- {
- CDialog::OnDestroy();
-
- // Select old bitmap into memory dc (selecting out circle bitmap)
- // Need to create a temporary pointer to pass to do this
- ASSERT( m_hBmpOld );
- VERIFY( m_dcMem.SelectObject( CBitmap::FromHandle(m_hBmpOld) ) );
-
- // Need to DeleteObject() bitmap which was loaded
- m_bmpCircle.DeleteObject();
-
- // m_dcMem destructor will handle rest of cleanup
- }
-
-
- //***********************************************************************
- // CPaintDlg::OnInitDialog()
- //
- // Purpose:
- //
- // Create compatible memory DC for dialog.
- // Load bitmap resource. Get bitmap size.
- // Select bitmap into memory DC and store handle to old bitmap.
- // Calculate size of dialogs client area for later StretchBlt()
- // of bitmap.
- // Load a hollow brush for later transparent painting of
- background
- // caused by modified OnCtlColor() handler.
- //
- // Parameters:
- //
- // None.
- //
- // Returns:
- //
- // BOOL (TRUE unless focus set to control)
- //
- // Comments:
- //
- // History:
- //
- // Date Comment Initials
- // ======== ================================================= ========
- // 10/30/93 Created TF
- //***********************************************************************
- /////////////////////////////////////////////////////////////////////////
- ////
- // IntroScreen message handlers
-
- BOOL introscreen::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- CBitmap * pBmpOld;
- RECT rectClient;
-
- // Load default brush;
- VERIFY( m_brush = (HBRUSH)GetStockObject( HOLLOW_BRUSH ) );
-
- // Load bitmap resource - remember to call DeleteObject when done.
- VERIFY( m_bmpCircle.LoadBitmap( IDB_BITMAP10 ) );
-
- // Get bitmap information
- m_bmpCircle.GetObject( sizeof(BITMAP), &m_bmInfo );
-
- GetClientRect( &rectClient );
-
- m_size.cx = rectClient.right; // zero based
- m_size.cy = rectClient.bottom; // zero based
- m_pt.x = rectClient.left;
- m_pt.y = rectClient.top;
-
- // Get temporary DC for dialog - Will be released in dc destructor
- CClientDC dc(this);
-
- // Create compatible memory DC using the dialogs DC
- VERIFY( m_dcMem.CreateCompatibleDC( &dc ) );
-
- // Select circle bitmap into DC.
- // Get pointer to original bitmap
- // NOTE! This is temporary - save the handle instead
- VERIFY( pBmpOld = m_dcMem.SelectObject( &m_bmpCircle ) );
-
- VERIFY( m_hBmpOld = (HBITMAP) pBmpOld->GetSafeHandle() );
-
- // local CCLientDC destructor for 'dc' will release device context
-
- button1 = new CBitmapButton();
- button2 = new CBitmapButton();
- button3 = new CBitmapButton();
- button4 = new CBitmapButton();
-
- VERIFY(button1->AutoLoad(IDC_IDDP, this)); //this
- button1->SizeToContent();
- #undef pete
- #ifdef pete
- VERIFY(button2->AutoLoad(IDC_IDITR, this));
- button2->SizeToContent();
- VERIFY(button3->AutoLoad(IDC_IDINS, this));
- VERIFY(button4->.AutoLoad(IDC_IDST, this));
- button3->SizeToContent();
- button4->SizeToContent();
- #endif
- // button1.EnableWindow(TRUE);
- // button2.EnableWindow(TRUE);
- // button3.EnableWindow(TRUE);
- // button4.EnableWindow(TRUE);
-
- return TRUE;
- }
-
-
- //***********************************************************************
- // IntroScreen::OnEraseBkgnd()
- //
- // Purpose:
- //
- // Paint background of dialog. In this case, use StretchBlt()
- // to paint a bitmap onto it.
- //
- // Parameters:
- //
- // None.
- //
- // Returns:
- //
- // BOOL (TRUE if no more background painting needed)
- //
- // Comments:
- //
- // History:
- //
- // Date Comment Initials
- // ======== ================================================= ========
- //
- //***********************************************************************
- BOOL introscreen::OnEraseBkgnd(CDC* pDC)
- {
- // StretchBlt Circle bitmap onto static's client area
- // pDC->StretchBlt( 240, m_pt.y + 80, m_size.cx - 240, m_size.cy - 80,
- // &m_dcMem, 0, 0, m_bmInfo.bmWidth-1,
- m_bmInfo.bmHeight-1,
- // SRCCOPY );
- pDC->StretchBlt( 0, 0, m_size.cx, m_size.cy,
- &m_dcMem, 0, 0, m_bmInfo.bmWidth-1,
- m_bmInfo.bmHeight-1,
- SRCCOPY );
- /*
- * First two parameters are upper left position to place bitmap.
- * Third and fourth parameters are width and height to copy to.
- * (could be less than actual size of bitmap)
- * Sixth and seventh are position in memory dc to start from
- * 8th and 9th are size of bitmap to copy from
- * SRCCOPY specifies copy.
- * See StretchBlt documentation for more details.
- */
-
- return TRUE; // No more background painting needed
- }
-
-
- int introscreen::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CDialog::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
-
- return 0;
- }
-
- void introscreen::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CDialog::OnShowWindow(bShow, nStatus);
-
- // TODO: Add your message handler code here
-
- }
-
-
-